<template>
    <div class="container">
        <!-- 路径导航区域 -->
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>回复表</el-breadcrumb-item>
            <el-breadcrumb-item>课程交流管理</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 搜索区域 -->
        <el-row>
            <el-form :inline="true">
                <el-form-item label="课程交流内容">
                    <el-input v-model="queryInfo.title" clearable @clear="queryList" placeholder="请输入课程交流内容"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="queryList">搜索</el-button>
                </el-form-item>
            </el-form>
        </el-row>
        <!-- 表格区域 -->
        <el-table :data="coursetalkList" border style="width: 100%" :header-cell-style="{'text-align':'center'}"
            :cell-style="{'text-align':'center'}">
            <el-table-column width="80" prop="id" label="ID"></el-table-column>
            <el-table-column prop="title" label="交流标题">
            </el-table-column>
            <el-table-column prop="createTime" label="创建时间">
            </el-table-column>
            <el-table-column prop="user.nickName" label="用户">
                <template slot-scope="scope">
                    <el-tag type="">{{ scope.row.user.nickName }}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="course.courseName" label="课程">
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope='scope'>
                    <el-button type="danger" icon="el-icon-delete" size="mini"
                        @click="deleteCoursetalk(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页区域 -->
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryInfo.pageNum" :page-sizes="[1, 5, 10, 15, 20]" :page-size="queryInfo.pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
    </div>
</template>
<script>
export default {
    data() {
        return {
            url: '',
            // 查询信息对象
            queryInfo: {
                title: '',
                pageNum: 1,
                pageSize: 10
            },
            total: 0,
            coursetalkList: [],
            coursetalk: {
                "id": '',
                "title": "",
                "createTime": "",
                "courseId": "",
                "userId": ""
            }
        }
    },
    methods: {
        // 删除
        deleteCoursetalk(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    this.$http.delete('coursetalk/' + id)
                        .then(resp => {
                            if (resp.data.status == 200) {
                                this.$message.success(resp.data.message)
                                this.queryList()
                            } else {
                                this.$message.error(resp.data.message)
                            }
                        })
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
        },
        queryList() {
            this.$http.get('coursetalk/findByPage', {
                params: this.queryInfo
            }).then(res => {
                if (res.data.status == 200) {
                    this.coursetalkList = res.data.data.list;
                    this.total = res.data.data.total
                } else {
                    this.$message.error('查询失败!')
                }
            })
        },
        handleSizeChange(size) {
            // console.log('每页显示数量发生改变');
            this.queryInfo.pageSize = size
            this.queryInfo.pageNum = 1
            this.queryList()
        },
        handleCurrentChange(num) {
            // console.log('页码发生改变');
            this.queryInfo.pageNum = num
            this.queryList()
        }
    },
    mounted() {
        this.queryList();
    }
}
</script>
<style>
.el-breadcrumb {
    margin-bottom: 15px;
    padding: 0 0 15px;
    border-bottom: 1px solid #ddd;
}

.el-pagination {
    margin-top: 15px;
}

.el-link {
    padding: 0 5px;
}
</style>